{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zkufh760uvF3"
      },
      "source": [
        "![JohnSnowLabs](https://nlp.johnsnowlabs.com/assets/images/logo.png)\n",
        "\n",
        "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JohnSnowLabs/nlu/blob/master/examples/colab/Training/binary_text_classification/NLU_training_sentiment_classifier_demo_stock_market.ipynb)\n",
        "\n",
        "\n",
        "# Training a Sentiment Analysis Classifier with NLU\n",
        "## 2 Class Demo  Stock Market Sentiment Training\n",
        "With the [SentimentDL model](https://nlp.johnsnowlabs.com/docs/en/annotators#sentimentdl-multi-class-sentiment-analysis-annotator)  from Spark NLP you can achieve State Of the Art results on any multi class text classification problem\n",
        "\n",
        "This notebook showcases the following features :\n",
        "\n",
        "- How to train the deep learning classifier\n",
        "- How to store a pipeline to disk\n",
        "- How to load the pipeline from disk (Enables NLU offline mode)\n",
        "\n",
        "\n",
        "You can achieve these results or even better on this dataset with training data:\n",
        "\n",
        "\n",
        "<br>\n",
        "\n",
        "\n",
        "![image.png]()\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "You can achieve these results or even better on this dataset with test  data:\n",
        "\n",
        "\n",
        "<br>\n",
        "\n",
        "![img.png]()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "dur2drhW5Rvi"
      },
      "source": [
        "# 1. Install Java 8 and NLU"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "hFGnBCHavltY"
      },
      "source": [
        "!pip install -q johnsnowlabs\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "f4KkTfnR5Ugg"
      },
      "source": [
        "# 2. Download Stock Market  Sentiment dataset\n",
        "https://www.kaggle.com/yash612/stockmarket-sentiment-dataset\n",
        "#Context\n",
        "\n",
        "Gathered Stock news from Multiple twitter Handles regarding Economic news dividing into two parts : Negative and positive."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "OrVb5ZMvvrQD"
      },
      "source": [
        "! wget https://s3.amazonaws.com/auxdata.johnsnowlabs.com/public/resources/en/classifier-dl/stock_data/stock_data.csv\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 424
        },
        "id": "y4xSRWIhwT28",
        "outputId": "2bb5e57a-472c-4812-dca5-aa29adad67ae"
      },
      "source": [
        "import pandas as pd\n",
        "train_path = '/content/stock_data.csv'\n",
        "\n",
        "train_df = pd.read_csv(train_path)\n",
        "# the text data to use for classification should be in a column named 'text'\n",
        "columns=['text','y']\n",
        "train_df = train_df[columns]\n",
        "train_df.y = train_df.y.astype(str)\n",
        "train_df.y = train_df.y.str.replace('-1','negative')\n",
        "train_df.y = train_df.y.str.replace('1','positive')\n",
        "from sklearn.model_selection import train_test_split\n",
        "\n",
        "train_df, test_df = train_test_split(train_df, test_size=0.2)\n",
        "train_df"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "                                                   text         y\n",
              "3971  Taking profits on CMG from 321, not time to a ...  positive\n",
              "4113  STI 5 min 1 - and 30 min opening range, added ...  positive\n",
              "1878         ong EN with stop arnd 39.40- entry 40.10    positive\n",
              "3270  Adding short BWS to portfolio. I think next ye...  negative\n",
              "5073  The banks for years rode consumer spending and...  negative\n",
              "...                                                 ...       ...\n",
              "5591  Sensex, Nifty End Mixed Despite RBI's Steep Re...  negative\n",
              "2338  ZNGA Merrill upgraded this on 2/5 - just a ret...  negative\n",
              "984   AMAT reached very high overbought conditions. ...  positive\n",
              "2883  GOOG reminds me so much of AAP in Sept  bounci...  negative\n",
              "4309  AAP 425 has been the BY target for the last fe...  positive\n",
              "\n",
              "[4632 rows x 2 columns]"
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-a095b6ba-d29a-49bf-91c2-a4ff9679e824\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>text</th>\n",
              "      <th>y</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>3971</th>\n",
              "      <td>Taking profits on CMG from 321, not time to a ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4113</th>\n",
              "      <td>STI 5 min 1 - and 30 min opening range, added ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1878</th>\n",
              "      <td>ong EN with stop arnd 39.40- entry 40.10</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3270</th>\n",
              "      <td>Adding short BWS to portfolio. I think next ye...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5073</th>\n",
              "      <td>The banks for years rode consumer spending and...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5591</th>\n",
              "      <td>Sensex, Nifty End Mixed Despite RBI's Steep Re...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2338</th>\n",
              "      <td>ZNGA Merrill upgraded this on 2/5 - just a ret...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>984</th>\n",
              "      <td>AMAT reached very high overbought conditions. ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2883</th>\n",
              "      <td>GOOG reminds me so much of AAP in Sept  bounci...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4309</th>\n",
              "      <td>AAP 425 has been the BY target for the last fe...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>4632 rows × 2 columns</p>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-a095b6ba-d29a-49bf-91c2-a4ff9679e824')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-a095b6ba-d29a-49bf-91c2-a4ff9679e824 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-a095b6ba-d29a-49bf-91c2-a4ff9679e824');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-3579e27a-be2c-4851-9d3e-fd7c1b98b39c\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-3579e27a-be2c-4851-9d3e-fd7c1b98b39c')\"\n",
              "            title=\"Suggest charts.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-3579e27a-be2c-4851-9d3e-fd7c1b98b39c button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 4
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0296Om2C5anY"
      },
      "source": [
        "# 3. Train Deep Learning Classifier using nlu.load('train.sentiment')\n",
        "\n",
        "You dataset label column should be named 'y' and the feature column with text data should be named 'text'"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "3ZIPkRkWftBG",
        "outputId": "91339d2a-72ec-490e-8531-2481e68d1447"
      },
      "source": [
        "from johnsnowlabs import nlp\n",
        "from sklearn.metrics import classification_report\n",
        "\n",
        "# load a trainable pipeline by specifying the train. prefix  and fit it on a datset with label and text columns\n",
        "# by default the Universal Sentence Encoder (USE) Sentence embeddings are used for generation\n",
        "trainable_pipe = nlp.load('train.sentiment')\n",
        "fitted_pipe = trainable_pipe.fit(train_df.iloc[:50])\n",
        "\n",
        "# predict with the trainable pipeline on dataset and get predictions\n",
        "preds = fitted_pipe.predict(train_df.iloc[:50],output_level='document')\n",
        "#sentence detector that is part of the pipe generates sone NaNs. lets drop them first\n",
        "preds.dropna(inplace=True)\n",
        "print(classification_report(preds['y'], preds['sentiment']))\n",
        "\n",
        "preds"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Warning::Spark Session already created, some configs may not take.\n",
            "sent_small_bert_L2_128 download started this may take some time.\n",
            "Approximate size to download 16.1 MB\n",
            "[OK!]\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/usr/local/lib/python3.10/dist-packages/nlu/pipe/pipeline.py:149: SettingWithCopyWarning: \n",
            "A value is trying to be set on a copy of a slice from a DataFrame.\n",
            "Try using .loc[row_indexer,col_indexer] = value instead\n",
            "\n",
            "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
            "  dataset.y = dataset.y.apply(str)\n",
            "/usr/local/lib/python3.10/dist-packages/nlu/pipe/utils/data_conversion_utils.py:160: SettingWithCopyWarning: \n",
            "A value is trying to be set on a copy of a slice from a DataFrame.\n",
            "Try using .loc[row_indexer,col_indexer] = value instead\n",
            "\n",
            "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
            "  data['origin_index'] = data.index\n",
            "/usr/local/lib/python3.10/dist-packages/nlu/pipe/utils/data_conversion_utils.py:160: SettingWithCopyWarning: \n",
            "A value is trying to be set on a copy of a slice from a DataFrame.\n",
            "Try using .loc[row_indexer,col_indexer] = value instead\n",
            "\n",
            "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
            "  data['origin_index'] = data.index\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "              precision    recall  f1-score   support\n",
            "\n",
            "    negative       0.00      0.00      0.00        17\n",
            "    positive       0.66      1.00      0.80        33\n",
            "\n",
            "    accuracy                           0.66        50\n",
            "   macro avg       0.33      0.50      0.40        50\n",
            "weighted avg       0.44      0.66      0.52        50\n",
            "\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/usr/local/lib/python3.10/dist-packages/nlu/pipe/extractors/extractor_methods/base_extractor_methods.py:356: SettingWithCopyWarning: \n",
            "A value is trying to be set on a copy of a slice from a DataFrame.\n",
            "Try using .loc[row_indexer,col_indexer] = value instead\n",
            "\n",
            "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
            "  df[cols_to_explode] = df[cols_to_explode].apply(pad_same_level_cols, axis=1)\n",
            "/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
            "  _warn_prf(average, modifier, msg_start, len(result))\n",
            "/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
            "  _warn_prf(average, modifier, msg_start, len(result))\n",
            "/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
            "  _warn_prf(average, modifier, msg_start, len(result))\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "                                             document  \\\n",
              "0   Taking profits on CMG from 321, not time to a ...   \n",
              "1   STI 5 min 1 - and 30 min opening range, added ...   \n",
              "2            ong EN with stop arnd 39.40- entry 40.10   \n",
              "3   Adding short BWS to portfolio. I think next ye...   \n",
              "4   The banks for years rode consumer spending and...   \n",
              "5   of some of the most watched biotechs AMGN look...   \n",
              "6   GOOG here is the leader of the pack for the ri...   \n",
              "7   user another good read. keep em coming and tha...   \n",
              "8   GTXI long 5.16, will take early assuming no ga...   \n",
              "9   Sen. Kelly Loeffler and her husband, New York ...   \n",
              "10  WMT if i had enough cash on hand i'd be shorti...   \n",
              "11  BAC Bank Of America Is The Best Bank Stock On ...   \n",
              "12  agree user: hedge funds sold AAP in Q4. We'll ...   \n",
              "13  user: Mr AAP is going to have to stop hanging ...   \n",
              "14           BAC Obama is slowing the rally... Ouch !   \n",
              "15  A couple biotech stocks that are setting up we...   \n",
              "16                                BAC next stop 10.50   \n",
              "17  STEM continuing move up - possiby getting some...   \n",
              "18                                CDX taking some off   \n",
              "19                 AJ stopped out +6% for a nice gain   \n",
              "20  with FCX gapping well above ideal entry lookin...   \n",
              "21  Rupee Edges Lower To 76.43 Against Dollar Amid...   \n",
              "22  ACX Today's P reads very positive.Would like t...   \n",
              "23  KWK this one is heavily oversold here, think w...   \n",
              "24         user: GEVO the beginning of a new uptrend:   \n",
              "25  Health insurance stocks should hold up fairly ...   \n",
              "26  CBMX that is unbelievable!!!!!!! but I am happ...   \n",
              "27  Global markets rise following fresh signals th...   \n",
              "28  My SHOTS, various strats, AXDX CMCO DGIT D ECY...   \n",
              "29   this could be the last good chance to short AMZN   \n",
              "30         HFC - Great group. ooks good. More here ->   \n",
              "31  RT @WSJheard: Heard on the Street's @jackycwon...   \n",
              "32  MON How quickly investors forget the massive b...   \n",
              "33  EA if price doesn't hold above 9SMA then 16.71...   \n",
              "34  NKD well above the moving averages, look for s...   \n",
              "35  AAP looking to take some off around 429, shoul...   \n",
              "36      Selling ICE Short check out my video analysis   \n",
              "37           CAT Bingo, it is Bingo everywhere today.   \n",
              "38                  HAO like it on a pop over 6 w vol   \n",
              "39  user: AAP nothing like firing of CEO to make i...   \n",
              "40  Coronavirus Crisis: GoAir Decides To Reduce Pa...   \n",
              "41  As the coronavirus pandemic intensifies, adher...   \n",
              "42  notable 52wk highs [20 > /sh < 50] AFCE AK ACO...   \n",
              "43  AAP PMI Manufacturing Index ---> In Few minute...   \n",
              "44  SPW pauses, SCTY continues its run, up > 20% i...   \n",
              "45  RT @josephttwallace: Glutted Oil Marketsâ€™ Ne...   \n",
              "46  GOOG keep in mind there are about 1,000 contra...   \n",
              "47  V and MA FYI: When they tagged the 50d's yeste...   \n",
              "48                               GOOG holding up well   \n",
              "49  JPMorgan Chase Chief Executive James Dimon ret...   \n",
              "\n",
              "                 sentence_embedding_small_bert_L2_128 sentiment  \\\n",
              "0   [-1.1575689315795898, 0.2715361416339874, -0.2...  positive   \n",
              "1   [-1.3090834617614746, -0.1740988940000534, -0....  positive   \n",
              "2   [-1.189386248588562, 0.4811112582683563, -0.66...  positive   \n",
              "3   [-0.6736384630203247, 0.7296571731567383, -0.1...  positive   \n",
              "4   [-0.3878522217273712, 0.5501695275306702, -0.0...  positive   \n",
              "5   [-0.31379231810569763, 0.5748125910758972, -0....  positive   \n",
              "6   [-0.5645806193351746, 0.6001827716827393, 0.08...  positive   \n",
              "7   [-1.0190978050231934, 0.7494890093803406, 0.07...  positive   \n",
              "8   [-0.2726511061191559, 0.32721856236457825, -0....  positive   \n",
              "9   [-0.28392985463142395, 1.012831449508667, -0.0...  positive   \n",
              "10  [-1.1887261867523193, 0.9961069226264954, -0.4...  positive   \n",
              "11  [0.3251396119594574, 0.9818293452262878, -0.51...  positive   \n",
              "12  [-0.5504413843154907, 1.0578975677490234, -0.3...  positive   \n",
              "13  [-0.5393702983856201, 1.2257893085479736, -0.2...  positive   \n",
              "14  [-1.0150749683380127, 0.10769235342741013, -0....  positive   \n",
              "15  [-0.09664952009916306, -0.05535533279180527, -...  positive   \n",
              "16  [-1.4360231161117554, 0.030535195022821426, -0...  positive   \n",
              "17  [-0.6773928999900818, 0.3930101990699768, -0.6...  positive   \n",
              "18  [-1.3559353351593018, 0.2133549153804779, -0.5...  positive   \n",
              "19  [-1.078188419342041, -0.23945243656635284, -0....  positive   \n",
              "20  [-0.7907727956771851, 0.7457559108734131, -0.3...  positive   \n",
              "21  [-0.41530898213386536, 0.15534837543964386, -0...  positive   \n",
              "22  [-0.8882211446762085, 0.13111452758312225, 0.1...  positive   \n",
              "23  [-0.4115653336048126, 0.23945458233356476, 0.2...  positive   \n",
              "24  [-0.8558018207550049, 0.20911763608455658, -0....  positive   \n",
              "25  [-0.6992183327674866, 0.873347282409668, -0.33...  positive   \n",
              "26  [-0.7398191690444946, 0.0032342064660042524, 0...  positive   \n",
              "27  [-0.46590617299079895, 0.5152156949043274, -0....  positive   \n",
              "28  [-0.9121986627578735, 0.18954770267009735, 0.5...  positive   \n",
              "29  [-1.4936555624008179, -0.08102501928806305, -0...  positive   \n",
              "30  [-1.282071590423584, 0.452540785074234, -0.020...  positive   \n",
              "31  [-0.16953450441360474, 0.5467158555984497, 0.4...  positive   \n",
              "32  [-1.0020204782485962, 0.06035422161221504, -0....  positive   \n",
              "33  [-0.6850847005844116, 0.7942832708358765, -0.2...  positive   \n",
              "34  [-1.168450117111206, 0.5925496816635132, -0.27...  positive   \n",
              "35  [-0.9121736884117126, 0.7181501388549805, -0.6...  positive   \n",
              "36  [-1.0185582637786865, 0.23524264991283417, -0....  positive   \n",
              "37  [-1.0476768016815186, -0.31251490116119385, 0....  positive   \n",
              "38  [-0.397280752658844, -0.7803610563278198, -0.0...  positive   \n",
              "39  [0.2457299381494522, 0.9597267508506775, -0.56...  positive   \n",
              "40  [-0.18016083538532257, 0.4278823137283325, -0....  positive   \n",
              "41  [-0.7261321544647217, -0.19837094843387604, -0...  positive   \n",
              "42  [-1.047921895980835, 0.6981227993965149, 0.153...  positive   \n",
              "43  [-0.7834053039550781, 0.5567207336425781, -0.6...  positive   \n",
              "44  [-0.8796350955963135, 0.21304339170455933, -0....  positive   \n",
              "45  [-0.24904966354370117, 0.5449734926223755, 0.1...  positive   \n",
              "46  [-0.6386780738830566, 0.6693974137306213, -0.7...  positive   \n",
              "47  [-1.3859288692474365, 0.1374266892671585, -0.2...  positive   \n",
              "48  [-0.9325542449951172, 0.7117096185684204, -0.2...  positive   \n",
              "49  [-0.5751636624336243, 0.5106868147850037, -0.1...  positive   \n",
              "\n",
              "   sentiment_confidence                                               text  \\\n",
              "0                   3.0  Taking profits on CMG from 321, not time to a ...   \n",
              "1                   3.0  STI 5 min 1 - and 30 min opening range, added ...   \n",
              "2                   2.0         ong EN with stop arnd 39.40- entry 40.10     \n",
              "3                   8.0  Adding short BWS to portfolio. I think next ye...   \n",
              "4                   6.0  The banks for years rode consumer spending and...   \n",
              "5                   3.0  of some of the most watched biotechs AMGN look...   \n",
              "6                   7.0  GOOG here is the leader of the pack for the ri...   \n",
              "7                   5.0  user another good read. keep em coming and tha...   \n",
              "8                   1.0  GTXI long 5.16, will take early assuming no ga...   \n",
              "9                   1.0  Sen. Kelly Loeffler and her husband, New York ...   \n",
              "10                  1.0  WMT if i had enough cash on hand i'd be shorti...   \n",
              "11                  2.0  BAC Bank Of America Is The Best Bank Stock On ...   \n",
              "12                  5.0  agree user: hedge funds sold AAP in Q4. We'll ...   \n",
              "13                  2.0  user: Mr AAP is going to have to stop hanging ...   \n",
              "14                  2.0           BAC Obama is slowing the rally... Ouch !   \n",
              "15                  2.0  A couple biotech stocks that are setting up we...   \n",
              "16                  2.0                                BAC next stop 10.50   \n",
              "17                  4.0  STEM continuing move up - possiby getting some...   \n",
              "18                  5.0                                CDX taking some off   \n",
              "19                  1.0               AJ stopped out +6% for a nice gain     \n",
              "20                  2.0  with FCX gapping well above ideal entry lookin...   \n",
              "21                  1.0  Rupee Edges Lower To 76.43 Against Dollar Amid...   \n",
              "22                  4.0  ACX Today's P reads very positive.Would like t...   \n",
              "23                  2.0  KWK this one is heavily oversold here, think w...   \n",
              "24                  7.0       user: GEVO the beginning of a new uptrend:     \n",
              "25                  1.0  Health insurance stocks should hold up fairly ...   \n",
              "26                  5.0  CBMX that is unbelievable!!!!!!!  but I am hap...   \n",
              "27                  5.0  Global markets rise following fresh signals th...   \n",
              "28                  8.0  My SHOTS, various strats, AXDX CMCO DGIT D ECY...   \n",
              "29                  5.0   this could be the last good chance to short AMZN   \n",
              "30                  1.0       HFC - Great group. ooks good. More here ->     \n",
              "31                  2.0  RT @WSJheard: Heard on the Street's @jackycwon...   \n",
              "32                  2.0  MON How quickly investors forget the massive b...   \n",
              "33                  2.0  EA if price doesn't hold above 9SMA then 16.71...   \n",
              "34                  3.0  NKD well above the moving averages, look for s...   \n",
              "35                  2.0  AAP looking to take some off around 429, shoul...   \n",
              "36                  1.0    Selling ICE Short check out my video analysis     \n",
              "37                  1.0           CAT Bingo, it is Bingo everywhere today.   \n",
              "38                  7.0                  HAO like it on a pop over 6 w vol   \n",
              "39                  2.0  user: AAP nothing like firing of CEO to make i...   \n",
              "40                  7.0  Coronavirus Crisis: GoAir Decides To Reduce Pa...   \n",
              "41                  3.0  As the coronavirus pandemic intensifies, adher...   \n",
              "42                  2.0  notable 52wk highs [20 > /sh < 50] AFCE AK ACO...   \n",
              "43                  6.0  AAP PMI Manufacturing Index ---> In Few minute...   \n",
              "44                  1.0  SPW pauses, SCTY continues its run, up > 20% i...   \n",
              "45                  1.0  RT @josephttwallace: Glutted Oil Marketsâ€™ Ne...   \n",
              "46                  3.0  GOOG keep in mind there are about 1,000 contra...   \n",
              "47                  2.0  V and MA FYI: When they tagged the 50d's yeste...   \n",
              "48                  4.0                               GOOG holding up well   \n",
              "49                  3.0  JPMorgan Chase Chief Executive James Dimon ret...   \n",
              "\n",
              "           y  \n",
              "0   positive  \n",
              "1   positive  \n",
              "2   positive  \n",
              "3   negative  \n",
              "4   negative  \n",
              "5   positive  \n",
              "6   negative  \n",
              "7   negative  \n",
              "8   positive  \n",
              "9   positive  \n",
              "10  negative  \n",
              "11  positive  \n",
              "12  positive  \n",
              "13  positive  \n",
              "14  negative  \n",
              "15  positive  \n",
              "16  negative  \n",
              "17  positive  \n",
              "18  positive  \n",
              "19  positive  \n",
              "20  positive  \n",
              "21  negative  \n",
              "22  positive  \n",
              "23  positive  \n",
              "24  positive  \n",
              "25  negative  \n",
              "26  positive  \n",
              "27  positive  \n",
              "28  negative  \n",
              "29  negative  \n",
              "30  positive  \n",
              "31  positive  \n",
              "32  positive  \n",
              "33  positive  \n",
              "34  positive  \n",
              "35  positive  \n",
              "36  negative  \n",
              "37  positive  \n",
              "38  positive  \n",
              "39  positive  \n",
              "40  negative  \n",
              "41  negative  \n",
              "42  positive  \n",
              "43  negative  \n",
              "44  positive  \n",
              "45  negative  \n",
              "46  negative  \n",
              "47  positive  \n",
              "48  positive  \n",
              "49  positive  "
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-81f0089d-58a7-4f82-a304-aab9f3dca4ab\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>document</th>\n",
              "      <th>sentence_embedding_small_bert_L2_128</th>\n",
              "      <th>sentiment</th>\n",
              "      <th>sentiment_confidence</th>\n",
              "      <th>text</th>\n",
              "      <th>y</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Taking profits on CMG from 321, not time to a ...</td>\n",
              "      <td>[-1.1575689315795898, 0.2715361416339874, -0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>Taking profits on CMG from 321, not time to a ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>STI 5 min 1 - and 30 min opening range, added ...</td>\n",
              "      <td>[-1.3090834617614746, -0.1740988940000534, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>STI 5 min 1 - and 30 min opening range, added ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>ong EN with stop arnd 39.40- entry 40.10</td>\n",
              "      <td>[-1.189386248588562, 0.4811112582683563, -0.66...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>ong EN with stop arnd 39.40- entry 40.10</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Adding short BWS to portfolio. I think next ye...</td>\n",
              "      <td>[-0.6736384630203247, 0.7296571731567383, -0.1...</td>\n",
              "      <td>positive</td>\n",
              "      <td>8.0</td>\n",
              "      <td>Adding short BWS to portfolio. I think next ye...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>The banks for years rode consumer spending and...</td>\n",
              "      <td>[-0.3878522217273712, 0.5501695275306702, -0.0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>6.0</td>\n",
              "      <td>The banks for years rode consumer spending and...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>of some of the most watched biotechs AMGN look...</td>\n",
              "      <td>[-0.31379231810569763, 0.5748125910758972, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>of some of the most watched biotechs AMGN look...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>GOOG here is the leader of the pack for the ri...</td>\n",
              "      <td>[-0.5645806193351746, 0.6001827716827393, 0.08...</td>\n",
              "      <td>positive</td>\n",
              "      <td>7.0</td>\n",
              "      <td>GOOG here is the leader of the pack for the ri...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>user another good read. keep em coming and tha...</td>\n",
              "      <td>[-1.0190978050231934, 0.7494890093803406, 0.07...</td>\n",
              "      <td>positive</td>\n",
              "      <td>5.0</td>\n",
              "      <td>user another good read. keep em coming and tha...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>GTXI long 5.16, will take early assuming no ga...</td>\n",
              "      <td>[-0.2726511061191559, 0.32721856236457825, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>GTXI long 5.16, will take early assuming no ga...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>Sen. Kelly Loeffler and her husband, New York ...</td>\n",
              "      <td>[-0.28392985463142395, 1.012831449508667, -0.0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>Sen. Kelly Loeffler and her husband, New York ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>WMT if i had enough cash on hand i'd be shorti...</td>\n",
              "      <td>[-1.1887261867523193, 0.9961069226264954, -0.4...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>WMT if i had enough cash on hand i'd be shorti...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>BAC Bank Of America Is The Best Bank Stock On ...</td>\n",
              "      <td>[0.3251396119594574, 0.9818293452262878, -0.51...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>BAC Bank Of America Is The Best Bank Stock On ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>agree user: hedge funds sold AAP in Q4. We'll ...</td>\n",
              "      <td>[-0.5504413843154907, 1.0578975677490234, -0.3...</td>\n",
              "      <td>positive</td>\n",
              "      <td>5.0</td>\n",
              "      <td>agree user: hedge funds sold AAP in Q4. We'll ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>user: Mr AAP is going to have to stop hanging ...</td>\n",
              "      <td>[-0.5393702983856201, 1.2257893085479736, -0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>user: Mr AAP is going to have to stop hanging ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>BAC Obama is slowing the rally... Ouch !</td>\n",
              "      <td>[-1.0150749683380127, 0.10769235342741013, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>BAC Obama is slowing the rally... Ouch !</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>A couple biotech stocks that are setting up we...</td>\n",
              "      <td>[-0.09664952009916306, -0.05535533279180527, -...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>A couple biotech stocks that are setting up we...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>BAC next stop 10.50</td>\n",
              "      <td>[-1.4360231161117554, 0.030535195022821426, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>BAC next stop 10.50</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>STEM continuing move up - possiby getting some...</td>\n",
              "      <td>[-0.6773928999900818, 0.3930101990699768, -0.6...</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>STEM continuing move up - possiby getting some...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>CDX taking some off</td>\n",
              "      <td>[-1.3559353351593018, 0.2133549153804779, -0.5...</td>\n",
              "      <td>positive</td>\n",
              "      <td>5.0</td>\n",
              "      <td>CDX taking some off</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>19</th>\n",
              "      <td>AJ stopped out +6% for a nice gain</td>\n",
              "      <td>[-1.078188419342041, -0.23945243656635284, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>AJ stopped out +6% for a nice gain</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20</th>\n",
              "      <td>with FCX gapping well above ideal entry lookin...</td>\n",
              "      <td>[-0.7907727956771851, 0.7457559108734131, -0.3...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>with FCX gapping well above ideal entry lookin...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>21</th>\n",
              "      <td>Rupee Edges Lower To 76.43 Against Dollar Amid...</td>\n",
              "      <td>[-0.41530898213386536, 0.15534837543964386, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>Rupee Edges Lower To 76.43 Against Dollar Amid...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>22</th>\n",
              "      <td>ACX Today's P reads very positive.Would like t...</td>\n",
              "      <td>[-0.8882211446762085, 0.13111452758312225, 0.1...</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>ACX Today's P reads very positive.Would like t...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>23</th>\n",
              "      <td>KWK this one is heavily oversold here, think w...</td>\n",
              "      <td>[-0.4115653336048126, 0.23945458233356476, 0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>KWK this one is heavily oversold here, think w...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>24</th>\n",
              "      <td>user: GEVO the beginning of a new uptrend:</td>\n",
              "      <td>[-0.8558018207550049, 0.20911763608455658, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>7.0</td>\n",
              "      <td>user: GEVO the beginning of a new uptrend:</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25</th>\n",
              "      <td>Health insurance stocks should hold up fairly ...</td>\n",
              "      <td>[-0.6992183327674866, 0.873347282409668, -0.33...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>Health insurance stocks should hold up fairly ...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>26</th>\n",
              "      <td>CBMX that is unbelievable!!!!!!! but I am happ...</td>\n",
              "      <td>[-0.7398191690444946, 0.0032342064660042524, 0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>5.0</td>\n",
              "      <td>CBMX that is unbelievable!!!!!!!  but I am hap...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>27</th>\n",
              "      <td>Global markets rise following fresh signals th...</td>\n",
              "      <td>[-0.46590617299079895, 0.5152156949043274, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>5.0</td>\n",
              "      <td>Global markets rise following fresh signals th...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>28</th>\n",
              "      <td>My SHOTS, various strats, AXDX CMCO DGIT D ECY...</td>\n",
              "      <td>[-0.9121986627578735, 0.18954770267009735, 0.5...</td>\n",
              "      <td>positive</td>\n",
              "      <td>8.0</td>\n",
              "      <td>My SHOTS, various strats, AXDX CMCO DGIT D ECY...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>29</th>\n",
              "      <td>this could be the last good chance to short AMZN</td>\n",
              "      <td>[-1.4936555624008179, -0.08102501928806305, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>5.0</td>\n",
              "      <td>this could be the last good chance to short AMZN</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>30</th>\n",
              "      <td>HFC - Great group. ooks good. More here -&gt;</td>\n",
              "      <td>[-1.282071590423584, 0.452540785074234, -0.020...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>HFC - Great group. ooks good. More here -&gt;</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>31</th>\n",
              "      <td>RT @WSJheard: Heard on the Street's @jackycwon...</td>\n",
              "      <td>[-0.16953450441360474, 0.5467158555984497, 0.4...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>RT @WSJheard: Heard on the Street's @jackycwon...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>32</th>\n",
              "      <td>MON How quickly investors forget the massive b...</td>\n",
              "      <td>[-1.0020204782485962, 0.06035422161221504, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>MON How quickly investors forget the massive b...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>33</th>\n",
              "      <td>EA if price doesn't hold above 9SMA then 16.71...</td>\n",
              "      <td>[-0.6850847005844116, 0.7942832708358765, -0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>EA if price doesn't hold above 9SMA then 16.71...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>34</th>\n",
              "      <td>NKD well above the moving averages, look for s...</td>\n",
              "      <td>[-1.168450117111206, 0.5925496816635132, -0.27...</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>NKD well above the moving averages, look for s...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>35</th>\n",
              "      <td>AAP looking to take some off around 429, shoul...</td>\n",
              "      <td>[-0.9121736884117126, 0.7181501388549805, -0.6...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>AAP looking to take some off around 429, shoul...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>36</th>\n",
              "      <td>Selling ICE Short check out my video analysis</td>\n",
              "      <td>[-1.0185582637786865, 0.23524264991283417, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>Selling ICE Short check out my video analysis</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>37</th>\n",
              "      <td>CAT Bingo, it is Bingo everywhere today.</td>\n",
              "      <td>[-1.0476768016815186, -0.31251490116119385, 0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>CAT Bingo, it is Bingo everywhere today.</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>38</th>\n",
              "      <td>HAO like it on a pop over 6 w vol</td>\n",
              "      <td>[-0.397280752658844, -0.7803610563278198, -0.0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>7.0</td>\n",
              "      <td>HAO like it on a pop over 6 w vol</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>39</th>\n",
              "      <td>user: AAP nothing like firing of CEO to make i...</td>\n",
              "      <td>[0.2457299381494522, 0.9597267508506775, -0.56...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>user: AAP nothing like firing of CEO to make i...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>40</th>\n",
              "      <td>Coronavirus Crisis: GoAir Decides To Reduce Pa...</td>\n",
              "      <td>[-0.18016083538532257, 0.4278823137283325, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>7.0</td>\n",
              "      <td>Coronavirus Crisis: GoAir Decides To Reduce Pa...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>41</th>\n",
              "      <td>As the coronavirus pandemic intensifies, adher...</td>\n",
              "      <td>[-0.7261321544647217, -0.19837094843387604, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>As the coronavirus pandemic intensifies, adher...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>42</th>\n",
              "      <td>notable 52wk highs [20 &gt; /sh &lt; 50] AFCE AK ACO...</td>\n",
              "      <td>[-1.047921895980835, 0.6981227993965149, 0.153...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>notable 52wk highs [20 &gt; /sh &lt; 50] AFCE AK ACO...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>43</th>\n",
              "      <td>AAP PMI Manufacturing Index ---&gt; In Few minute...</td>\n",
              "      <td>[-0.7834053039550781, 0.5567207336425781, -0.6...</td>\n",
              "      <td>positive</td>\n",
              "      <td>6.0</td>\n",
              "      <td>AAP PMI Manufacturing Index ---&gt; In Few minute...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>44</th>\n",
              "      <td>SPW pauses, SCTY continues its run, up &gt; 20% i...</td>\n",
              "      <td>[-0.8796350955963135, 0.21304339170455933, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>SPW pauses, SCTY continues its run, up &gt; 20% i...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>45</th>\n",
              "      <td>RT @josephttwallace: Glutted Oil Marketsâ€™ Ne...</td>\n",
              "      <td>[-0.24904966354370117, 0.5449734926223755, 0.1...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>RT @josephttwallace: Glutted Oil Marketsâ€™ Ne...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>46</th>\n",
              "      <td>GOOG keep in mind there are about 1,000 contra...</td>\n",
              "      <td>[-0.6386780738830566, 0.6693974137306213, -0.7...</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>GOOG keep in mind there are about 1,000 contra...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>47</th>\n",
              "      <td>V and MA FYI: When they tagged the 50d's yeste...</td>\n",
              "      <td>[-1.3859288692474365, 0.1374266892671585, -0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>V and MA FYI: When they tagged the 50d's yeste...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>48</th>\n",
              "      <td>GOOG holding up well</td>\n",
              "      <td>[-0.9325542449951172, 0.7117096185684204, -0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>GOOG holding up well</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>49</th>\n",
              "      <td>JPMorgan Chase Chief Executive James Dimon ret...</td>\n",
              "      <td>[-0.5751636624336243, 0.5106868147850037, -0.1...</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>JPMorgan Chase Chief Executive James Dimon ret...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-81f0089d-58a7-4f82-a304-aab9f3dca4ab')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-81f0089d-58a7-4f82-a304-aab9f3dca4ab button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-81f0089d-58a7-4f82-a304-aab9f3dca4ab');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-b5350296-683d-462a-bd62-2840e7afa962\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-b5350296-683d-462a-bd62-2840e7afa962')\"\n",
              "            title=\"Suggest charts.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-b5350296-683d-462a-bd62-2840e7afa962 button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 6
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "lVyOE2wV0fw_"
      },
      "source": [
        "# 4. Test the fitted pipe on new example"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 150
        },
        "id": "qdCUg2MR0PD2",
        "outputId": "3c226560-fe14-42eb-e537-0535e6d0819f"
      },
      "source": [
        "fitted_pipe.predict(\"Bitcoin dropped by 50 percent!\")"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "sentence_detector_dl download started this may take some time.\n",
            "Approximate size to download 354.6 KB\n",
            "[OK!]\n",
            "Warning::Spark Session already created, some configs may not take.\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "                         sentence  \\\n",
              "0  Bitcoin dropped by 50 percent!   \n",
              "\n",
              "                sentence_embedding_small_bert_L2_128 sentiment  \\\n",
              "0  [-1.7797279357910156, 0.3090762495994568, -0.2...  positive   \n",
              "\n",
              "  sentiment_confidence  \n",
              "0                  1.0  "
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-9f35dbca-6d52-4961-813c-fa05bbcd1797\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>sentence</th>\n",
              "      <th>sentence_embedding_small_bert_L2_128</th>\n",
              "      <th>sentiment</th>\n",
              "      <th>sentiment_confidence</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Bitcoin dropped by 50 percent!</td>\n",
              "      <td>[-1.7797279357910156, 0.3090762495994568, -0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-9f35dbca-6d52-4961-813c-fa05bbcd1797')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-9f35dbca-6d52-4961-813c-fa05bbcd1797 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-9f35dbca-6d52-4961-813c-fa05bbcd1797');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 7
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xflpwrVjjBVD"
      },
      "source": [
        "## 5.  Configure pipe training parameters"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "UtsAUGTmOTms",
        "outputId": "f9404635-50b4-4278-b7e1-95f0c05692ff"
      },
      "source": [
        "trainable_pipe.print_info()"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The following parameters are configurable for this NLU pipeline (You can copy paste the examples) :\n",
            ">>> component_list['bert_sentence_embeddings@sent_small_bert_L2_128'] has settable params:\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setBatchSize(8)              | Info: Size of every batch | Currently set to : 8\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setEngine('tensorflow')      | Info: Deep Learning engine used for this model | Currently set to : tensorflow\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setIsLong(False)             | Info: Use Long type instead of Int type for inputs buffer - Some Bert models require Long instead of Int. | Currently set to : False\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setMaxSentenceLength(128)    | Info: Max sentence length to process | Currently set to : 128\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setDimension(128)            | Info: Number of embedding dimensions | Currently set to : 128\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setCaseSensitive(False)      | Info: whether to ignore case in tokens for embeddings matching | Currently set to : False\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L2_128'].setStorageRef('sent_small_bert_L2_128')  | Info: unique reference name for identification | Currently set to : sent_small_bert_L2_128\n",
            ">>> component_list['document_assembler'] has settable params:\n",
            "component_list['document_assembler'].setCleanupMode('shrink')                                  | Info: possible values: disabled, inplace, inplace_full, shrink, shrink_full, each, each_full, delete_full | Currently set to : shrink\n",
            ">>> component_list['sentiment_dl@sent_small_bert_L2_128'] has settable params:\n",
            "component_list['sentiment_dl@sent_small_bert_L2_128'].setEngine('tensorflow')                  | Info: Deep Learning engine used for this model | Currently set to : tensorflow\n",
            "component_list['sentiment_dl@sent_small_bert_L2_128'].setThreshold(0.6)                        | Info: The minimum threshold for the final result otheriwse it will be neutral | Currently set to : 0.6\n",
            "component_list['sentiment_dl@sent_small_bert_L2_128'].setThresholdLabel('neutral')             | Info: In case the score is less than threshold, what should be the label. Default is neutral. | Currently set to : neutral\n",
            "component_list['sentiment_dl@sent_small_bert_L2_128'].setStorageRef('sent_small_bert_L2_128')  | Info: unique reference name for identification | Currently set to : sent_small_bert_L2_128\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2GJdDNV9jEIe"
      },
      "source": [
        "## 6. Retrain with new parameters"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "mptfvHx-MMMX",
        "outputId": "bf0f4962-bb67-4c9a-c92c-96b64cbfdf51"
      },
      "source": [
        "# Train longer!\n",
        "trainable_pipe = nlp.load('train.sentiment')\n",
        "trainable_pipe['trainable_sentiment_dl'].setMaxEpochs(5)\n",
        "fitted_pipe = trainable_pipe.fit(train_df.iloc[:50])\n",
        "# predict with the trainable pipeline on dataset and get predictions\n",
        "preds = fitted_pipe.predict(train_df.iloc[:50],output_level='document')\n",
        "\n",
        "#sentence detector that is part of the pipe generates sone NaNs. lets drop them first\n",
        "preds.dropna(inplace=True)\n",
        "print(classification_report(preds['y'], preds['sentiment']))\n",
        "\n",
        "preds"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Warning::Spark Session already created, some configs may not take.\n",
            "Warning::Spark Session already created, some configs may not take.\n",
            "sent_small_bert_L2_128 download started this may take some time.\n",
            "Approximate size to download 16.1 MB\n",
            "[OK!]\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/usr/local/lib/python3.10/dist-packages/nlu/pipe/pipeline.py:149: SettingWithCopyWarning: \n",
            "A value is trying to be set on a copy of a slice from a DataFrame.\n",
            "Try using .loc[row_indexer,col_indexer] = value instead\n",
            "\n",
            "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
            "  dataset.y = dataset.y.apply(str)\n",
            "/usr/local/lib/python3.10/dist-packages/nlu/pipe/utils/data_conversion_utils.py:160: SettingWithCopyWarning: \n",
            "A value is trying to be set on a copy of a slice from a DataFrame.\n",
            "Try using .loc[row_indexer,col_indexer] = value instead\n",
            "\n",
            "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
            "  data['origin_index'] = data.index\n",
            "/usr/local/lib/python3.10/dist-packages/nlu/pipe/utils/data_conversion_utils.py:160: SettingWithCopyWarning: \n",
            "A value is trying to be set on a copy of a slice from a DataFrame.\n",
            "Try using .loc[row_indexer,col_indexer] = value instead\n",
            "\n",
            "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
            "  data['origin_index'] = data.index\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "              precision    recall  f1-score   support\n",
            "\n",
            "    negative       0.00      0.00      0.00        17\n",
            "    positive       0.66      1.00      0.80        33\n",
            "\n",
            "    accuracy                           0.66        50\n",
            "   macro avg       0.33      0.50      0.40        50\n",
            "weighted avg       0.44      0.66      0.52        50\n",
            "\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/usr/local/lib/python3.10/dist-packages/nlu/pipe/extractors/extractor_methods/base_extractor_methods.py:356: SettingWithCopyWarning: \n",
            "A value is trying to be set on a copy of a slice from a DataFrame.\n",
            "Try using .loc[row_indexer,col_indexer] = value instead\n",
            "\n",
            "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
            "  df[cols_to_explode] = df[cols_to_explode].apply(pad_same_level_cols, axis=1)\n",
            "/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
            "  _warn_prf(average, modifier, msg_start, len(result))\n",
            "/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
            "  _warn_prf(average, modifier, msg_start, len(result))\n",
            "/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
            "  _warn_prf(average, modifier, msg_start, len(result))\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "                                             document  \\\n",
              "0   Taking profits on CMG from 321, not time to a ...   \n",
              "1   STI 5 min 1 - and 30 min opening range, added ...   \n",
              "2            ong EN with stop arnd 39.40- entry 40.10   \n",
              "3   Adding short BWS to portfolio. I think next ye...   \n",
              "4   The banks for years rode consumer spending and...   \n",
              "5   of some of the most watched biotechs AMGN look...   \n",
              "6   GOOG here is the leader of the pack for the ri...   \n",
              "7   user another good read. keep em coming and tha...   \n",
              "8   GTXI long 5.16, will take early assuming no ga...   \n",
              "9   Sen. Kelly Loeffler and her husband, New York ...   \n",
              "10  WMT if i had enough cash on hand i'd be shorti...   \n",
              "11  BAC Bank Of America Is The Best Bank Stock On ...   \n",
              "12  agree user: hedge funds sold AAP in Q4. We'll ...   \n",
              "13  user: Mr AAP is going to have to stop hanging ...   \n",
              "14           BAC Obama is slowing the rally... Ouch !   \n",
              "15  A couple biotech stocks that are setting up we...   \n",
              "16                                BAC next stop 10.50   \n",
              "17  STEM continuing move up - possiby getting some...   \n",
              "18                                CDX taking some off   \n",
              "19                 AJ stopped out +6% for a nice gain   \n",
              "20  with FCX gapping well above ideal entry lookin...   \n",
              "21  Rupee Edges Lower To 76.43 Against Dollar Amid...   \n",
              "22  ACX Today's P reads very positive.Would like t...   \n",
              "23  KWK this one is heavily oversold here, think w...   \n",
              "24         user: GEVO the beginning of a new uptrend:   \n",
              "25  Health insurance stocks should hold up fairly ...   \n",
              "26  CBMX that is unbelievable!!!!!!! but I am happ...   \n",
              "27  Global markets rise following fresh signals th...   \n",
              "28  My SHOTS, various strats, AXDX CMCO DGIT D ECY...   \n",
              "29   this could be the last good chance to short AMZN   \n",
              "30         HFC - Great group. ooks good. More here ->   \n",
              "31  RT @WSJheard: Heard on the Street's @jackycwon...   \n",
              "32  MON How quickly investors forget the massive b...   \n",
              "33  EA if price doesn't hold above 9SMA then 16.71...   \n",
              "34  NKD well above the moving averages, look for s...   \n",
              "35  AAP looking to take some off around 429, shoul...   \n",
              "36      Selling ICE Short check out my video analysis   \n",
              "37           CAT Bingo, it is Bingo everywhere today.   \n",
              "38                  HAO like it on a pop over 6 w vol   \n",
              "39  user: AAP nothing like firing of CEO to make i...   \n",
              "40  Coronavirus Crisis: GoAir Decides To Reduce Pa...   \n",
              "41  As the coronavirus pandemic intensifies, adher...   \n",
              "42  notable 52wk highs [20 > /sh < 50] AFCE AK ACO...   \n",
              "43  AAP PMI Manufacturing Index ---> In Few minute...   \n",
              "44  SPW pauses, SCTY continues its run, up > 20% i...   \n",
              "45  RT @josephttwallace: Glutted Oil Marketsâ€™ Ne...   \n",
              "46  GOOG keep in mind there are about 1,000 contra...   \n",
              "47  V and MA FYI: When they tagged the 50d's yeste...   \n",
              "48                               GOOG holding up well   \n",
              "49  JPMorgan Chase Chief Executive James Dimon ret...   \n",
              "\n",
              "                 sentence_embedding_small_bert_L2_128 sentiment  \\\n",
              "0   [-1.1575689315795898, 0.2715361416339874, -0.2...  positive   \n",
              "1   [-1.3090834617614746, -0.1740988940000534, -0....  positive   \n",
              "2   [-1.189386248588562, 0.4811112582683563, -0.66...  positive   \n",
              "3   [-0.6736384630203247, 0.7296571731567383, -0.1...  positive   \n",
              "4   [-0.3878522217273712, 0.5501695275306702, -0.0...  positive   \n",
              "5   [-0.31379231810569763, 0.5748125910758972, -0....  positive   \n",
              "6   [-0.5645806193351746, 0.6001827716827393, 0.08...  positive   \n",
              "7   [-1.0190978050231934, 0.7494890093803406, 0.07...  positive   \n",
              "8   [-0.2726511061191559, 0.32721856236457825, -0....  positive   \n",
              "9   [-0.28392985463142395, 1.012831449508667, -0.0...  positive   \n",
              "10  [-1.1887261867523193, 0.9961069226264954, -0.4...  positive   \n",
              "11  [0.3251396119594574, 0.9818293452262878, -0.51...  positive   \n",
              "12  [-0.5504413843154907, 1.0578975677490234, -0.3...  positive   \n",
              "13  [-0.5393702983856201, 1.2257893085479736, -0.2...  positive   \n",
              "14  [-1.0150749683380127, 0.10769235342741013, -0....  positive   \n",
              "15  [-0.09664952009916306, -0.05535533279180527, -...  positive   \n",
              "16  [-1.4360231161117554, 0.030535195022821426, -0...  positive   \n",
              "17  [-0.6773928999900818, 0.3930101990699768, -0.6...  positive   \n",
              "18  [-1.3559353351593018, 0.2133549153804779, -0.5...  positive   \n",
              "19  [-1.078188419342041, -0.23945243656635284, -0....  positive   \n",
              "20  [-0.7907727956771851, 0.7457559108734131, -0.3...  positive   \n",
              "21  [-0.41530898213386536, 0.15534837543964386, -0...  positive   \n",
              "22  [-0.8882211446762085, 0.13111452758312225, 0.1...  positive   \n",
              "23  [-0.4115653336048126, 0.23945458233356476, 0.2...  positive   \n",
              "24  [-0.8558018207550049, 0.20911763608455658, -0....  positive   \n",
              "25  [-0.6992183327674866, 0.873347282409668, -0.33...  positive   \n",
              "26  [-0.7398191690444946, 0.0032342064660042524, 0...  positive   \n",
              "27  [-0.46590617299079895, 0.5152156949043274, -0....  positive   \n",
              "28  [-0.9121986627578735, 0.18954770267009735, 0.5...  positive   \n",
              "29  [-1.4936555624008179, -0.08102501928806305, -0...  positive   \n",
              "30  [-1.282071590423584, 0.452540785074234, -0.020...  positive   \n",
              "31  [-0.16953450441360474, 0.5467158555984497, 0.4...  positive   \n",
              "32  [-1.0020204782485962, 0.06035422161221504, -0....  positive   \n",
              "33  [-0.6850847005844116, 0.7942832708358765, -0.2...  positive   \n",
              "34  [-1.168450117111206, 0.5925496816635132, -0.27...  positive   \n",
              "35  [-0.9121736884117126, 0.7181501388549805, -0.6...  positive   \n",
              "36  [-1.0185582637786865, 0.23524264991283417, -0....  positive   \n",
              "37  [-1.0476768016815186, -0.31251490116119385, 0....  positive   \n",
              "38  [-0.397280752658844, -0.7803610563278198, -0.0...  positive   \n",
              "39  [0.2457299381494522, 0.9597267508506775, -0.56...  positive   \n",
              "40  [-0.18016083538532257, 0.4278823137283325, -0....  positive   \n",
              "41  [-0.7261321544647217, -0.19837094843387604, -0...  positive   \n",
              "42  [-1.047921895980835, 0.6981227993965149, 0.153...  positive   \n",
              "43  [-0.7834053039550781, 0.5567207336425781, -0.6...  positive   \n",
              "44  [-0.8796350955963135, 0.21304339170455933, -0....  positive   \n",
              "45  [-0.24904966354370117, 0.5449734926223755, 0.1...  positive   \n",
              "46  [-0.6386780738830566, 0.6693974137306213, -0.7...  positive   \n",
              "47  [-1.3859288692474365, 0.1374266892671585, -0.2...  positive   \n",
              "48  [-0.9325542449951172, 0.7117096185684204, -0.2...  positive   \n",
              "49  [-0.5751636624336243, 0.5106868147850037, -0.1...  positive   \n",
              "\n",
              "   sentiment_confidence                                               text  \\\n",
              "0                   4.0  Taking profits on CMG from 321, not time to a ...   \n",
              "1                   7.0  STI 5 min 1 - and 30 min opening range, added ...   \n",
              "2                   4.0         ong EN with stop arnd 39.40- entry 40.10     \n",
              "3                   7.0  Adding short BWS to portfolio. I think next ye...   \n",
              "4                   4.0  The banks for years rode consumer spending and...   \n",
              "5                   1.0  of some of the most watched biotechs AMGN look...   \n",
              "6                   5.0  GOOG here is the leader of the pack for the ri...   \n",
              "7                   1.0  user another good read. keep em coming and tha...   \n",
              "8                   7.0  GTXI long 5.16, will take early assuming no ga...   \n",
              "9                   1.0  Sen. Kelly Loeffler and her husband, New York ...   \n",
              "10                  9.0  WMT if i had enough cash on hand i'd be shorti...   \n",
              "11                  9.0  BAC Bank Of America Is The Best Bank Stock On ...   \n",
              "12                  3.0  agree user: hedge funds sold AAP in Q4. We'll ...   \n",
              "13                  2.0  user: Mr AAP is going to have to stop hanging ...   \n",
              "14                  1.0           BAC Obama is slowing the rally... Ouch !   \n",
              "15                  5.0  A couple biotech stocks that are setting up we...   \n",
              "16                  1.0                                BAC next stop 10.50   \n",
              "17                  8.0  STEM continuing move up - possiby getting some...   \n",
              "18                  1.0                                CDX taking some off   \n",
              "19                  5.0               AJ stopped out +6% for a nice gain     \n",
              "20                  4.0  with FCX gapping well above ideal entry lookin...   \n",
              "21                  4.0  Rupee Edges Lower To 76.43 Against Dollar Amid...   \n",
              "22                  1.0  ACX Today's P reads very positive.Would like t...   \n",
              "23                  2.0  KWK this one is heavily oversold here, think w...   \n",
              "24                  8.0       user: GEVO the beginning of a new uptrend:     \n",
              "25                  4.0  Health insurance stocks should hold up fairly ...   \n",
              "26                  2.0  CBMX that is unbelievable!!!!!!!  but I am hap...   \n",
              "27                  4.0  Global markets rise following fresh signals th...   \n",
              "28                  3.0  My SHOTS, various strats, AXDX CMCO DGIT D ECY...   \n",
              "29                  1.0   this could be the last good chance to short AMZN   \n",
              "30                  6.0       HFC - Great group. ooks good. More here ->     \n",
              "31                  3.0  RT @WSJheard: Heard on the Street's @jackycwon...   \n",
              "32                  2.0  MON How quickly investors forget the massive b...   \n",
              "33                  2.0  EA if price doesn't hold above 9SMA then 16.71...   \n",
              "34                  7.0  NKD well above the moving averages, look for s...   \n",
              "35                  8.0  AAP looking to take some off around 429, shoul...   \n",
              "36                  1.0    Selling ICE Short check out my video analysis     \n",
              "37                  1.0           CAT Bingo, it is Bingo everywhere today.   \n",
              "38                  2.0                  HAO like it on a pop over 6 w vol   \n",
              "39                  4.0  user: AAP nothing like firing of CEO to make i...   \n",
              "40                  8.0  Coronavirus Crisis: GoAir Decides To Reduce Pa...   \n",
              "41                  6.0  As the coronavirus pandemic intensifies, adher...   \n",
              "42                  7.0  notable 52wk highs [20 > /sh < 50] AFCE AK ACO...   \n",
              "43                  7.0  AAP PMI Manufacturing Index ---> In Few minute...   \n",
              "44                  3.0  SPW pauses, SCTY continues its run, up > 20% i...   \n",
              "45                  2.0  RT @josephttwallace: Glutted Oil Marketsâ€™ Ne...   \n",
              "46                  4.0  GOOG keep in mind there are about 1,000 contra...   \n",
              "47                  1.0  V and MA FYI: When they tagged the 50d's yeste...   \n",
              "48                  2.0                               GOOG holding up well   \n",
              "49                  6.0  JPMorgan Chase Chief Executive James Dimon ret...   \n",
              "\n",
              "           y  \n",
              "0   positive  \n",
              "1   positive  \n",
              "2   positive  \n",
              "3   negative  \n",
              "4   negative  \n",
              "5   positive  \n",
              "6   negative  \n",
              "7   negative  \n",
              "8   positive  \n",
              "9   positive  \n",
              "10  negative  \n",
              "11  positive  \n",
              "12  positive  \n",
              "13  positive  \n",
              "14  negative  \n",
              "15  positive  \n",
              "16  negative  \n",
              "17  positive  \n",
              "18  positive  \n",
              "19  positive  \n",
              "20  positive  \n",
              "21  negative  \n",
              "22  positive  \n",
              "23  positive  \n",
              "24  positive  \n",
              "25  negative  \n",
              "26  positive  \n",
              "27  positive  \n",
              "28  negative  \n",
              "29  negative  \n",
              "30  positive  \n",
              "31  positive  \n",
              "32  positive  \n",
              "33  positive  \n",
              "34  positive  \n",
              "35  positive  \n",
              "36  negative  \n",
              "37  positive  \n",
              "38  positive  \n",
              "39  positive  \n",
              "40  negative  \n",
              "41  negative  \n",
              "42  positive  \n",
              "43  negative  \n",
              "44  positive  \n",
              "45  negative  \n",
              "46  negative  \n",
              "47  positive  \n",
              "48  positive  \n",
              "49  positive  "
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-65352499-252d-45f9-a04b-710fbc59c864\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>document</th>\n",
              "      <th>sentence_embedding_small_bert_L2_128</th>\n",
              "      <th>sentiment</th>\n",
              "      <th>sentiment_confidence</th>\n",
              "      <th>text</th>\n",
              "      <th>y</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Taking profits on CMG from 321, not time to a ...</td>\n",
              "      <td>[-1.1575689315795898, 0.2715361416339874, -0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>Taking profits on CMG from 321, not time to a ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>STI 5 min 1 - and 30 min opening range, added ...</td>\n",
              "      <td>[-1.3090834617614746, -0.1740988940000534, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>7.0</td>\n",
              "      <td>STI 5 min 1 - and 30 min opening range, added ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>ong EN with stop arnd 39.40- entry 40.10</td>\n",
              "      <td>[-1.189386248588562, 0.4811112582683563, -0.66...</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>ong EN with stop arnd 39.40- entry 40.10</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Adding short BWS to portfolio. I think next ye...</td>\n",
              "      <td>[-0.6736384630203247, 0.7296571731567383, -0.1...</td>\n",
              "      <td>positive</td>\n",
              "      <td>7.0</td>\n",
              "      <td>Adding short BWS to portfolio. I think next ye...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>The banks for years rode consumer spending and...</td>\n",
              "      <td>[-0.3878522217273712, 0.5501695275306702, -0.0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>The banks for years rode consumer spending and...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>of some of the most watched biotechs AMGN look...</td>\n",
              "      <td>[-0.31379231810569763, 0.5748125910758972, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>of some of the most watched biotechs AMGN look...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>GOOG here is the leader of the pack for the ri...</td>\n",
              "      <td>[-0.5645806193351746, 0.6001827716827393, 0.08...</td>\n",
              "      <td>positive</td>\n",
              "      <td>5.0</td>\n",
              "      <td>GOOG here is the leader of the pack for the ri...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>user another good read. keep em coming and tha...</td>\n",
              "      <td>[-1.0190978050231934, 0.7494890093803406, 0.07...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>user another good read. keep em coming and tha...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>GTXI long 5.16, will take early assuming no ga...</td>\n",
              "      <td>[-0.2726511061191559, 0.32721856236457825, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>7.0</td>\n",
              "      <td>GTXI long 5.16, will take early assuming no ga...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>Sen. Kelly Loeffler and her husband, New York ...</td>\n",
              "      <td>[-0.28392985463142395, 1.012831449508667, -0.0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>Sen. Kelly Loeffler and her husband, New York ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>WMT if i had enough cash on hand i'd be shorti...</td>\n",
              "      <td>[-1.1887261867523193, 0.9961069226264954, -0.4...</td>\n",
              "      <td>positive</td>\n",
              "      <td>9.0</td>\n",
              "      <td>WMT if i had enough cash on hand i'd be shorti...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>BAC Bank Of America Is The Best Bank Stock On ...</td>\n",
              "      <td>[0.3251396119594574, 0.9818293452262878, -0.51...</td>\n",
              "      <td>positive</td>\n",
              "      <td>9.0</td>\n",
              "      <td>BAC Bank Of America Is The Best Bank Stock On ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>agree user: hedge funds sold AAP in Q4. We'll ...</td>\n",
              "      <td>[-0.5504413843154907, 1.0578975677490234, -0.3...</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>agree user: hedge funds sold AAP in Q4. We'll ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>user: Mr AAP is going to have to stop hanging ...</td>\n",
              "      <td>[-0.5393702983856201, 1.2257893085479736, -0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>user: Mr AAP is going to have to stop hanging ...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>BAC Obama is slowing the rally... Ouch !</td>\n",
              "      <td>[-1.0150749683380127, 0.10769235342741013, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>BAC Obama is slowing the rally... Ouch !</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>A couple biotech stocks that are setting up we...</td>\n",
              "      <td>[-0.09664952009916306, -0.05535533279180527, -...</td>\n",
              "      <td>positive</td>\n",
              "      <td>5.0</td>\n",
              "      <td>A couple biotech stocks that are setting up we...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>BAC next stop 10.50</td>\n",
              "      <td>[-1.4360231161117554, 0.030535195022821426, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>BAC next stop 10.50</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>STEM continuing move up - possiby getting some...</td>\n",
              "      <td>[-0.6773928999900818, 0.3930101990699768, -0.6...</td>\n",
              "      <td>positive</td>\n",
              "      <td>8.0</td>\n",
              "      <td>STEM continuing move up - possiby getting some...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>CDX taking some off</td>\n",
              "      <td>[-1.3559353351593018, 0.2133549153804779, -0.5...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>CDX taking some off</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>19</th>\n",
              "      <td>AJ stopped out +6% for a nice gain</td>\n",
              "      <td>[-1.078188419342041, -0.23945243656635284, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>5.0</td>\n",
              "      <td>AJ stopped out +6% for a nice gain</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20</th>\n",
              "      <td>with FCX gapping well above ideal entry lookin...</td>\n",
              "      <td>[-0.7907727956771851, 0.7457559108734131, -0.3...</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>with FCX gapping well above ideal entry lookin...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>21</th>\n",
              "      <td>Rupee Edges Lower To 76.43 Against Dollar Amid...</td>\n",
              "      <td>[-0.41530898213386536, 0.15534837543964386, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>Rupee Edges Lower To 76.43 Against Dollar Amid...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>22</th>\n",
              "      <td>ACX Today's P reads very positive.Would like t...</td>\n",
              "      <td>[-0.8882211446762085, 0.13111452758312225, 0.1...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>ACX Today's P reads very positive.Would like t...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>23</th>\n",
              "      <td>KWK this one is heavily oversold here, think w...</td>\n",
              "      <td>[-0.4115653336048126, 0.23945458233356476, 0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>KWK this one is heavily oversold here, think w...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>24</th>\n",
              "      <td>user: GEVO the beginning of a new uptrend:</td>\n",
              "      <td>[-0.8558018207550049, 0.20911763608455658, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>8.0</td>\n",
              "      <td>user: GEVO the beginning of a new uptrend:</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25</th>\n",
              "      <td>Health insurance stocks should hold up fairly ...</td>\n",
              "      <td>[-0.6992183327674866, 0.873347282409668, -0.33...</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>Health insurance stocks should hold up fairly ...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>26</th>\n",
              "      <td>CBMX that is unbelievable!!!!!!! but I am happ...</td>\n",
              "      <td>[-0.7398191690444946, 0.0032342064660042524, 0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>CBMX that is unbelievable!!!!!!!  but I am hap...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>27</th>\n",
              "      <td>Global markets rise following fresh signals th...</td>\n",
              "      <td>[-0.46590617299079895, 0.5152156949043274, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>Global markets rise following fresh signals th...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>28</th>\n",
              "      <td>My SHOTS, various strats, AXDX CMCO DGIT D ECY...</td>\n",
              "      <td>[-0.9121986627578735, 0.18954770267009735, 0.5...</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>My SHOTS, various strats, AXDX CMCO DGIT D ECY...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>29</th>\n",
              "      <td>this could be the last good chance to short AMZN</td>\n",
              "      <td>[-1.4936555624008179, -0.08102501928806305, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>this could be the last good chance to short AMZN</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>30</th>\n",
              "      <td>HFC - Great group. ooks good. More here -&gt;</td>\n",
              "      <td>[-1.282071590423584, 0.452540785074234, -0.020...</td>\n",
              "      <td>positive</td>\n",
              "      <td>6.0</td>\n",
              "      <td>HFC - Great group. ooks good. More here -&gt;</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>31</th>\n",
              "      <td>RT @WSJheard: Heard on the Street's @jackycwon...</td>\n",
              "      <td>[-0.16953450441360474, 0.5467158555984497, 0.4...</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>RT @WSJheard: Heard on the Street's @jackycwon...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>32</th>\n",
              "      <td>MON How quickly investors forget the massive b...</td>\n",
              "      <td>[-1.0020204782485962, 0.06035422161221504, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>MON How quickly investors forget the massive b...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>33</th>\n",
              "      <td>EA if price doesn't hold above 9SMA then 16.71...</td>\n",
              "      <td>[-0.6850847005844116, 0.7942832708358765, -0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>EA if price doesn't hold above 9SMA then 16.71...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>34</th>\n",
              "      <td>NKD well above the moving averages, look for s...</td>\n",
              "      <td>[-1.168450117111206, 0.5925496816635132, -0.27...</td>\n",
              "      <td>positive</td>\n",
              "      <td>7.0</td>\n",
              "      <td>NKD well above the moving averages, look for s...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>35</th>\n",
              "      <td>AAP looking to take some off around 429, shoul...</td>\n",
              "      <td>[-0.9121736884117126, 0.7181501388549805, -0.6...</td>\n",
              "      <td>positive</td>\n",
              "      <td>8.0</td>\n",
              "      <td>AAP looking to take some off around 429, shoul...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>36</th>\n",
              "      <td>Selling ICE Short check out my video analysis</td>\n",
              "      <td>[-1.0185582637786865, 0.23524264991283417, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>Selling ICE Short check out my video analysis</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>37</th>\n",
              "      <td>CAT Bingo, it is Bingo everywhere today.</td>\n",
              "      <td>[-1.0476768016815186, -0.31251490116119385, 0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>CAT Bingo, it is Bingo everywhere today.</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>38</th>\n",
              "      <td>HAO like it on a pop over 6 w vol</td>\n",
              "      <td>[-0.397280752658844, -0.7803610563278198, -0.0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>HAO like it on a pop over 6 w vol</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>39</th>\n",
              "      <td>user: AAP nothing like firing of CEO to make i...</td>\n",
              "      <td>[0.2457299381494522, 0.9597267508506775, -0.56...</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>user: AAP nothing like firing of CEO to make i...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>40</th>\n",
              "      <td>Coronavirus Crisis: GoAir Decides To Reduce Pa...</td>\n",
              "      <td>[-0.18016083538532257, 0.4278823137283325, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>8.0</td>\n",
              "      <td>Coronavirus Crisis: GoAir Decides To Reduce Pa...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>41</th>\n",
              "      <td>As the coronavirus pandemic intensifies, adher...</td>\n",
              "      <td>[-0.7261321544647217, -0.19837094843387604, -0...</td>\n",
              "      <td>positive</td>\n",
              "      <td>6.0</td>\n",
              "      <td>As the coronavirus pandemic intensifies, adher...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>42</th>\n",
              "      <td>notable 52wk highs [20 &gt; /sh &lt; 50] AFCE AK ACO...</td>\n",
              "      <td>[-1.047921895980835, 0.6981227993965149, 0.153...</td>\n",
              "      <td>positive</td>\n",
              "      <td>7.0</td>\n",
              "      <td>notable 52wk highs [20 &gt; /sh &lt; 50] AFCE AK ACO...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>43</th>\n",
              "      <td>AAP PMI Manufacturing Index ---&gt; In Few minute...</td>\n",
              "      <td>[-0.7834053039550781, 0.5567207336425781, -0.6...</td>\n",
              "      <td>positive</td>\n",
              "      <td>7.0</td>\n",
              "      <td>AAP PMI Manufacturing Index ---&gt; In Few minute...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>44</th>\n",
              "      <td>SPW pauses, SCTY continues its run, up &gt; 20% i...</td>\n",
              "      <td>[-0.8796350955963135, 0.21304339170455933, -0....</td>\n",
              "      <td>positive</td>\n",
              "      <td>3.0</td>\n",
              "      <td>SPW pauses, SCTY continues its run, up &gt; 20% i...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>45</th>\n",
              "      <td>RT @josephttwallace: Glutted Oil Marketsâ€™ Ne...</td>\n",
              "      <td>[-0.24904966354370117, 0.5449734926223755, 0.1...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>RT @josephttwallace: Glutted Oil Marketsâ€™ Ne...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>46</th>\n",
              "      <td>GOOG keep in mind there are about 1,000 contra...</td>\n",
              "      <td>[-0.6386780738830566, 0.6693974137306213, -0.7...</td>\n",
              "      <td>positive</td>\n",
              "      <td>4.0</td>\n",
              "      <td>GOOG keep in mind there are about 1,000 contra...</td>\n",
              "      <td>negative</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>47</th>\n",
              "      <td>V and MA FYI: When they tagged the 50d's yeste...</td>\n",
              "      <td>[-1.3859288692474365, 0.1374266892671585, -0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>1.0</td>\n",
              "      <td>V and MA FYI: When they tagged the 50d's yeste...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>48</th>\n",
              "      <td>GOOG holding up well</td>\n",
              "      <td>[-0.9325542449951172, 0.7117096185684204, -0.2...</td>\n",
              "      <td>positive</td>\n",
              "      <td>2.0</td>\n",
              "      <td>GOOG holding up well</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>49</th>\n",
              "      <td>JPMorgan Chase Chief Executive James Dimon ret...</td>\n",
              "      <td>[-0.5751636624336243, 0.5106868147850037, -0.1...</td>\n",
              "      <td>positive</td>\n",
              "      <td>6.0</td>\n",
              "      <td>JPMorgan Chase Chief Executive James Dimon ret...</td>\n",
              "      <td>positive</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-65352499-252d-45f9-a04b-710fbc59c864')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-65352499-252d-45f9-a04b-710fbc59c864 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-65352499-252d-45f9-a04b-710fbc59c864');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-8ae7a102-9df3-40df-a563-cb875973a87a\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-8ae7a102-9df3-40df-a563-cb875973a87a')\"\n",
              "            title=\"Suggest charts.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-8ae7a102-9df3-40df-a563-cb875973a87a button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 9
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qFoT-s1MjTSS"
      },
      "source": [
        "# 7. Try training with different Embeddings"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "nxWFzQOhjWC8",
        "outputId": "017238a7-20f7-432a-ecff-d987390c1221"
      },
      "source": [
        "# We can use nlu.print_components(action='embed_sentence') to see every possibler sentence embedding we could use. Lets use bert!\n",
        "nlp.nlu.print_components(action='embed_sentence')"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "For language <am> NLU provides the following Models : \n",
            "nlu.load('am.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_amharic\n",
            "For language <de> NLU provides the following Models : \n",
            "nlu.load('de.embed_sentence.bert.base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
            "For language <el> NLU provides the following Models : \n",
            "nlu.load('el.embed_sentence.bert.base_uncased') returns Spark NLP model_anno_obj sent_bert_base_uncased\n",
            "For language <en> NLU provides the following Models : \n",
            "nlu.load('en.embed_sentence') returns Spark NLP model_anno_obj tfhub_use\n",
            "nlu.load('en.embed_sentence.albert') returns Spark NLP model_anno_obj albert_base_uncased\n",
            "nlu.load('en.embed_sentence.bert') returns Spark NLP model_anno_obj sent_bert_base_uncased\n",
            "nlu.load('en.embed_sentence.bert.base_uncased_legal') returns Spark NLP model_anno_obj sent_bert_base_uncased_legal\n",
            "nlu.load('en.embed_sentence.bert.finetuned') returns Spark NLP model_anno_obj sbert_setfit_finetuned_financial_text_classification\n",
            "nlu.load('en.embed_sentence.bert.pubmed') returns Spark NLP model_anno_obj sent_bert_pubmed\n",
            "nlu.load('en.embed_sentence.bert.pubmed_squad2') returns Spark NLP model_anno_obj sent_bert_pubmed_squad2\n",
            "nlu.load('en.embed_sentence.bert.wiki_books') returns Spark NLP model_anno_obj sent_bert_wiki_books\n",
            "nlu.load('en.embed_sentence.bert.wiki_books_mnli') returns Spark NLP model_anno_obj sent_bert_wiki_books_mnli\n",
            "nlu.load('en.embed_sentence.bert.wiki_books_qnli') returns Spark NLP model_anno_obj sent_bert_wiki_books_qnli\n",
            "nlu.load('en.embed_sentence.bert.wiki_books_qqp') returns Spark NLP model_anno_obj sent_bert_wiki_books_qqp\n",
            "nlu.load('en.embed_sentence.bert.wiki_books_squad2') returns Spark NLP model_anno_obj sent_bert_wiki_books_squad2\n",
            "nlu.load('en.embed_sentence.bert.wiki_books_sst2') returns Spark NLP model_anno_obj sent_bert_wiki_books_sst2\n",
            "nlu.load('en.embed_sentence.bert_base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
            "nlu.load('en.embed_sentence.bert_base_uncased') returns Spark NLP model_anno_obj sent_bert_base_uncased\n",
            "nlu.load('en.embed_sentence.bert_large_cased') returns Spark NLP model_anno_obj sent_bert_large_cased\n",
            "nlu.load('en.embed_sentence.bert_large_uncased') returns Spark NLP model_anno_obj sent_bert_large_uncased\n",
            "nlu.load('en.embed_sentence.bert_use_cmlm_en_base') returns Spark NLP model_anno_obj sent_bert_use_cmlm_en_base\n",
            "nlu.load('en.embed_sentence.bert_use_cmlm_en_large') returns Spark NLP model_anno_obj sent_bert_use_cmlm_en_large\n",
            "nlu.load('en.embed_sentence.biobert.clinical_base_cased') returns Spark NLP model_anno_obj sent_biobert_clinical_base_cased\n",
            "nlu.load('en.embed_sentence.biobert.discharge_base_cased') returns Spark NLP model_anno_obj sent_biobert_discharge_base_cased\n",
            "nlu.load('en.embed_sentence.biobert.pmc_base_cased') returns Spark NLP model_anno_obj sent_biobert_pmc_base_cased\n",
            "nlu.load('en.embed_sentence.biobert.pubmed_base_cased') returns Spark NLP model_anno_obj sent_biobert_pubmed_base_cased\n",
            "nlu.load('en.embed_sentence.biobert.pubmed_large_cased') returns Spark NLP model_anno_obj sent_biobert_pubmed_large_cased\n",
            "nlu.load('en.embed_sentence.biobert.pubmed_pmc_base_cased') returns Spark NLP model_anno_obj sent_biobert_pubmed_pmc_base_cased\n",
            "nlu.load('en.embed_sentence.covidbert.large_uncased') returns Spark NLP model_anno_obj sent_covidbert_large_uncased\n",
            "nlu.load('en.embed_sentence.distil_roberta.distilled_base') returns Spark NLP model_anno_obj sent_distilroberta_base\n",
            "nlu.load('en.embed_sentence.doc2vec') returns Spark NLP model_anno_obj doc2vec_gigaword_300\n",
            "nlu.load('en.embed_sentence.doc2vec.gigaword_300') returns Spark NLP model_anno_obj doc2vec_gigaword_300\n",
            "nlu.load('en.embed_sentence.doc2vec.gigaword_wiki_300') returns Spark NLP model_anno_obj doc2vec_gigaword_wiki_300\n",
            "nlu.load('en.embed_sentence.electra') returns Spark NLP model_anno_obj sent_electra_small_uncased\n",
            "nlu.load('en.embed_sentence.electra_base_uncased') returns Spark NLP model_anno_obj sent_electra_base_uncased\n",
            "nlu.load('en.embed_sentence.electra_large_uncased') returns Spark NLP model_anno_obj sent_electra_large_uncased\n",
            "nlu.load('en.embed_sentence.electra_small_uncased') returns Spark NLP model_anno_obj sent_electra_small_uncased\n",
            "nlu.load('en.embed_sentence.roberta.base') returns Spark NLP model_anno_obj sent_roberta_base\n",
            "nlu.load('en.embed_sentence.roberta.large') returns Spark NLP model_anno_obj sent_roberta_large\n",
            "nlu.load('en.embed_sentence.small_bert_L10_128') returns Spark NLP model_anno_obj sent_small_bert_L10_128\n",
            "nlu.load('en.embed_sentence.small_bert_L10_256') returns Spark NLP model_anno_obj sent_small_bert_L10_256\n",
            "nlu.load('en.embed_sentence.small_bert_L10_512') returns Spark NLP model_anno_obj sent_small_bert_L10_512\n",
            "nlu.load('en.embed_sentence.small_bert_L10_768') returns Spark NLP model_anno_obj sent_small_bert_L10_768\n",
            "nlu.load('en.embed_sentence.small_bert_L12_128') returns Spark NLP model_anno_obj sent_small_bert_L12_128\n",
            "nlu.load('en.embed_sentence.small_bert_L12_256') returns Spark NLP model_anno_obj sent_small_bert_L12_256\n",
            "nlu.load('en.embed_sentence.small_bert_L12_512') returns Spark NLP model_anno_obj sent_small_bert_L12_512\n",
            "nlu.load('en.embed_sentence.small_bert_L12_768') returns Spark NLP model_anno_obj sent_small_bert_L12_768\n",
            "nlu.load('en.embed_sentence.small_bert_L2_128') returns Spark NLP model_anno_obj sent_small_bert_L2_128\n",
            "nlu.load('en.embed_sentence.small_bert_L2_256') returns Spark NLP model_anno_obj sent_small_bert_L2_256\n",
            "nlu.load('en.embed_sentence.small_bert_L2_512') returns Spark NLP model_anno_obj sent_small_bert_L2_512\n",
            "nlu.load('en.embed_sentence.small_bert_L2_768') returns Spark NLP model_anno_obj sent_small_bert_L2_768\n",
            "nlu.load('en.embed_sentence.small_bert_L4_128') returns Spark NLP model_anno_obj sent_small_bert_L4_128\n",
            "nlu.load('en.embed_sentence.small_bert_L4_256') returns Spark NLP model_anno_obj sent_small_bert_L4_256\n",
            "nlu.load('en.embed_sentence.small_bert_L4_512') returns Spark NLP model_anno_obj sent_small_bert_L4_512\n",
            "nlu.load('en.embed_sentence.small_bert_L4_768') returns Spark NLP model_anno_obj sent_small_bert_L4_768\n",
            "nlu.load('en.embed_sentence.small_bert_L6_128') returns Spark NLP model_anno_obj sent_small_bert_L6_128\n",
            "nlu.load('en.embed_sentence.small_bert_L6_256') returns Spark NLP model_anno_obj sent_small_bert_L6_256\n",
            "nlu.load('en.embed_sentence.small_bert_L6_512') returns Spark NLP model_anno_obj sent_small_bert_L6_512\n",
            "nlu.load('en.embed_sentence.small_bert_L6_768') returns Spark NLP model_anno_obj sent_small_bert_L6_768\n",
            "nlu.load('en.embed_sentence.small_bert_L8_128') returns Spark NLP model_anno_obj sent_small_bert_L8_128\n",
            "nlu.load('en.embed_sentence.small_bert_L8_256') returns Spark NLP model_anno_obj sent_small_bert_L8_256\n",
            "nlu.load('en.embed_sentence.small_bert_L8_512') returns Spark NLP model_anno_obj sent_small_bert_L8_512\n",
            "nlu.load('en.embed_sentence.small_bert_L8_768') returns Spark NLP model_anno_obj sent_small_bert_L8_768\n",
            "nlu.load('en.embed_sentence.tfhub_use') returns Spark NLP model_anno_obj tfhub_use\n",
            "nlu.load('en.embed_sentence.tfhub_use.lg') returns Spark NLP model_anno_obj tfhub_use_lg\n",
            "nlu.load('en.embed_sentence.use') returns Spark NLP model_anno_obj tfhub_use\n",
            "nlu.load('en.embed_sentence.use.lg') returns Spark NLP model_anno_obj tfhub_use_lg\n",
            "For language <es> NLU provides the following Models : \n",
            "nlu.load('es.embed_sentence.bert.base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
            "nlu.load('es.embed_sentence.bert.base_uncased') returns Spark NLP model_anno_obj sent_bert_base_uncased\n",
            "For language <fi> NLU provides the following Models : \n",
            "nlu.load('fi.embed_sentence.bert') returns Spark NLP model_anno_obj bert_base_finnish_uncased\n",
            "nlu.load('fi.embed_sentence.bert.cased') returns Spark NLP model_anno_obj bert_base_finnish_cased\n",
            "nlu.load('fi.embed_sentence.bert.uncased') returns Spark NLP model_anno_obj bert_base_finnish_uncased\n",
            "For language <ha> NLU provides the following Models : \n",
            "nlu.load('ha.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_hausa\n",
            "For language <ig> NLU provides the following Models : \n",
            "nlu.load('ig.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_igbo\n",
            "For language <lg> NLU provides the following Models : \n",
            "nlu.load('lg.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_luganda\n",
            "For language <nl> NLU provides the following Models : \n",
            "nlu.load('nl.embed_sentence.bert.base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
            "For language <pcm> NLU provides the following Models : \n",
            "nlu.load('pcm.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_naija\n",
            "For language <pt> NLU provides the following Models : \n",
            "nlu.load('pt.embed_sentence.bert.base_legal') returns Spark NLP model_anno_obj sbert_legal_bertimbau_base_tsdae_sts\n",
            "nlu.load('pt.embed_sentence.bert.cased_large_legal') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.1\n",
            "nlu.load('pt.embed_sentence.bert.large_legal') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_gpl_sts\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.10.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.10\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.2.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.2\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.3.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.3\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.4.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.4\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.5.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.5\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.7.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.7\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.8.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.8\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v0.9.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v0.9\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_sts_v1.0.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_sts_v1.0\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_gpl_nli_sts_v0.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_gpl_nli_sts_v0\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_gpl_nli_sts_v1.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_gpl_nli_sts_v1\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_nli_sts_v0.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_nli_sts_v0\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_nli_sts_v1.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_nli_sts_v1\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_sts_v0.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_sts_v0\n",
            "nlu.load('pt.embed_sentence.bert.legal.cased_large_mlm_v0.11_sts_v1.by_stjiris') returns Spark NLP model_anno_obj sbert_bert_large_portuguese_cased_legal_mlm_v0.11_sts_v1\n",
            "nlu.load('pt.embed_sentence.bert.v2_base_legal') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_base_ma_v2\n",
            "nlu.load('pt.embed_sentence.bert.v2_large_legal') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_tsdae_sts_v2\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.assin.base.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_base_ma\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.assin2.base.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_base\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.large_sts_by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_large\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.large_sts_ma.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_large_ma\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.large_sts_ma_v3.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_large_ma_v3\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.large_tsdae_sts.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_tsdae_sts\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.large_tsdae_sts_v4.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_tsdae_sts_v4\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.large_tsdae_v4_gpl_sts.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_tsdae_v4_gpl_sts\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.v2_large_sts_v2.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_sts_large_v2\n",
            "nlu.load('pt.embed_sentence.bertimbau.legal.v2_large_v2_sts.by_rufimelo') returns Spark NLP model_anno_obj sbert_legal_bertimbau_large_v2_sts\n",
            "For language <rw> NLU provides the following Models : \n",
            "nlu.load('rw.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_kinyarwanda\n",
            "For language <sv> NLU provides the following Models : \n",
            "nlu.load('sv.embed_sentence.bert.base_cased') returns Spark NLP model_anno_obj sent_bert_base_cased\n",
            "For language <sw> NLU provides the following Models : \n",
            "nlu.load('sw.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_swahili\n",
            "For language <wo> NLU provides the following Models : \n",
            "nlu.load('wo.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_wolof\n",
            "For language <xx> NLU provides the following Models : \n",
            "nlu.load('xx.embed_sentence') returns Spark NLP model_anno_obj sent_bert_multi_cased\n",
            "nlu.load('xx.embed_sentence.bert') returns Spark NLP model_anno_obj sent_bert_multi_cased\n",
            "nlu.load('xx.embed_sentence.bert.cased') returns Spark NLP model_anno_obj sent_bert_multi_cased\n",
            "nlu.load('xx.embed_sentence.bert.muril') returns Spark NLP model_anno_obj sent_bert_muril\n",
            "nlu.load('xx.embed_sentence.bert_use_cmlm_multi_base') returns Spark NLP model_anno_obj sent_bert_use_cmlm_multi_base\n",
            "nlu.load('xx.embed_sentence.bert_use_cmlm_multi_base_br') returns Spark NLP model_anno_obj sent_bert_use_cmlm_multi_base_br\n",
            "nlu.load('xx.embed_sentence.labse') returns Spark NLP model_anno_obj labse\n",
            "nlu.load('xx.embed_sentence.xlm_roberta.base') returns Spark NLP model_anno_obj sent_xlm_roberta_base\n",
            "For language <yo> NLU provides the following Models : \n",
            "nlu.load('yo.embed_sentence.xlm_roberta') returns Spark NLP model_anno_obj sent_xlm_roberta_base_finetuned_yoruba\n",
            "For language <zh> NLU provides the following Models : \n",
            "nlu.load('zh.embed_sentence.bert') returns Spark NLP model_anno_obj sbert_chinese_qmc_finance_v1\n",
            "nlu.load('zh.embed_sentence.bert.distilled') returns Spark NLP model_anno_obj sbert_chinese_qmc_finance_v1_distill\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "IKK_Ii_gjJfF",
        "outputId": "34ce4144-5adf-404e-a0aa-aec86b7ff166"
      },
      "source": [
        "trainable_pipe = nlp.load('en.embed_sentence.small_bert_L12_768 train.sentiment')\n",
        "# We need to train longer and user smaller LR for NON-USE based sentence embeddings usually\n",
        "# We could tune the hyperparameters further with hyperparameter tuning methods like gridsearch\n",
        "# Also longer training gives more accuracy\n",
        "trainable_pipe['trainable_sentiment_dl'].setMaxEpochs(120)\n",
        "trainable_pipe['trainable_sentiment_dl'].setLr(0.0005)\n",
        "fitted_pipe = trainable_pipe.fit(train_df)\n",
        "# predict with the trainable pipeline on dataset and get predictions\n",
        "preds = fitted_pipe.predict(train_df,output_level='document')\n",
        "\n",
        "#sentence detector that is part of the pipe generates sone NaNs. lets drop them first\n",
        "preds.dropna(inplace=True)\n",
        "print(classification_report(preds['y'], preds['sentiment']))\n",
        "\n",
        "#preds"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Warning::Spark Session already created, some configs may not take.\n",
            "Warning::Spark Session already created, some configs may not take.\n",
            "sent_small_bert_L12_768 download started this may take some time.\n",
            "Approximate size to download 392.9 MB\n",
            "[OK!]\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/usr/local/lib/python3.10/dist-packages/nlu/pipe/extractors/extractor_methods/base_extractor_methods.py:356: SettingWithCopyWarning: \n",
            "A value is trying to be set on a copy of a slice from a DataFrame.\n",
            "Try using .loc[row_indexer,col_indexer] = value instead\n",
            "\n",
            "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
            "  df[cols_to_explode] = df[cols_to_explode].apply(pad_same_level_cols, axis=1)\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "              precision    recall  f1-score   support\n",
            "\n",
            "    negative       0.79      0.54      0.64      1671\n",
            "     neutral       0.00      0.00      0.00         0\n",
            "    positive       0.82      0.86      0.84      2961\n",
            "\n",
            "    accuracy                           0.74      4632\n",
            "   macro avg       0.54      0.46      0.49      4632\n",
            "weighted avg       0.81      0.74      0.76      4632\n",
            "\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
            "  _warn_prf(average, modifier, msg_start, len(result))\n",
            "/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
            "  _warn_prf(average, modifier, msg_start, len(result))\n",
            "/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
            "  _warn_prf(average, modifier, msg_start, len(result))\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_1jxw3GnVGlI"
      },
      "source": [
        "# 7.1 evaluate on Test Data"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Fxx4yNkNVGFl",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "c788a55c-8686-4835-e3d4-c8fa5551cae0"
      },
      "source": [
        "preds = fitted_pipe.predict(test_df,output_level='document')\n",
        "\n",
        "#sentence detector that is part of the pipe generates sone NaNs. lets drop them first\n",
        "preds.dropna(inplace=True)\n",
        "print(classification_report(preds['y'], preds['sentiment']))"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "              precision    recall  f1-score   support\n",
            "\n",
            "    negative       0.69      0.45      0.54       435\n",
            "     neutral       0.00      0.00      0.00         0\n",
            "    positive       0.76      0.80      0.78       724\n",
            "\n",
            "    accuracy                           0.67      1159\n",
            "   macro avg       0.48      0.41      0.44      1159\n",
            "weighted avg       0.73      0.67      0.69      1159\n",
            "\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/usr/local/lib/python3.10/dist-packages/nlu/pipe/extractors/extractor_methods/base_extractor_methods.py:356: SettingWithCopyWarning: \n",
            "A value is trying to be set on a copy of a slice from a DataFrame.\n",
            "Try using .loc[row_indexer,col_indexer] = value instead\n",
            "\n",
            "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
            "  df[cols_to_explode] = df[cols_to_explode].apply(pad_same_level_cols, axis=1)\n",
            "/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
            "  _warn_prf(average, modifier, msg_start, len(result))\n",
            "/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
            "  _warn_prf(average, modifier, msg_start, len(result))\n",
            "/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\n",
            "  _warn_prf(average, modifier, msg_start, len(result))\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2BB-NwZUoHSe"
      },
      "source": [
        "# 8. Lets save the model"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "eLex095goHwm"
      },
      "source": [
        "stored_model_path = './models/classifier_dl_trained'\n",
        "fitted_pipe.save(stored_model_path)"
      ],
      "execution_count": 14,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "e_b2DPd4rCiU"
      },
      "source": [
        "# 9. Lets load the model from HDD.\n",
        "This makes Offlien NLU usage possible!   \n",
        "You need to call nlu.load(path=path_to_the_pipe) to load a model/pipeline from disk."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 133
        },
        "id": "SO4uz45MoRgp",
        "outputId": "d78b4bfd-544c-4add-9583-9356de5ebb7e"
      },
      "source": [
        "hdd_pipe = nlp.load(path=\"./models/classifier_dl_trained\")\n",
        "\n",
        "preds = hdd_pipe.predict('Bitcoin dropped by 50 percent!!')\n",
        "preds"
      ],
      "execution_count": 15,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Warning::Spark Session already created, some configs may not take.\n",
            "Warning::Spark Session already created, some configs may not take.\n",
            "Warning::Spark Session already created, some configs may not take.\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "                          document  \\\n",
              "0  Bitcoin dropped by 50 percent!!   \n",
              "\n",
              "                        sentence_embedding_from_disk sentiment  \\\n",
              "0  [0.20597122609615326, 0.16840754449367523, 0.0...  negative   \n",
              "\n",
              "  sentiment_confidence  \n",
              "0                  0.0  "
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-68500ccd-2a38-499f-97b2-5910c8698914\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>document</th>\n",
              "      <th>sentence_embedding_from_disk</th>\n",
              "      <th>sentiment</th>\n",
              "      <th>sentiment_confidence</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Bitcoin dropped by 50 percent!!</td>\n",
              "      <td>[0.20597122609615326, 0.16840754449367523, 0.0...</td>\n",
              "      <td>negative</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-68500ccd-2a38-499f-97b2-5910c8698914')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-68500ccd-2a38-499f-97b2-5910c8698914 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-68500ccd-2a38-499f-97b2-5910c8698914');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ]
          },
          "metadata": {},
          "execution_count": 15
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "e0CVlkk9v6Qi",
        "outputId": "ae53e7f2-6371-4473-ca8e-5074f5341f31"
      },
      "source": [
        "hdd_pipe.print_info()"
      ],
      "execution_count": 16,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The following parameters are configurable for this NLU pipeline (You can copy paste the examples) :\n",
            ">>> component_list['document_assembler'] has settable params:\n",
            "component_list['document_assembler'].setCleanupMode('shrink')                                    | Info: possible values: disabled, inplace, inplace_full, shrink, shrink_full, each, each_full, delete_full | Currently set to : shrink\n",
            ">>> component_list['bert_sentence_embeddings@sent_small_bert_L12_768'] has settable params:\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setBatchSize(8)               | Info: Size of every batch | Currently set to : 8\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setCaseSensitive(False)       | Info: whether to ignore case in tokens for embeddings matching | Currently set to : False\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setDimension(768)             | Info: Number of embedding dimensions | Currently set to : 768\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setMaxSentenceLength(128)     | Info: Max sentence length to process | Currently set to : 128\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setEngine('tensorflow')       | Info: Deep Learning engine used for this model | Currently set to : tensorflow\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setIsLong(False)              | Info: Use Long type instead of Int type for inputs buffer - Some Bert models require Long instead of Int. | Currently set to : False\n",
            "component_list['bert_sentence_embeddings@sent_small_bert_L12_768'].setStorageRef('sent_small_bert_L12_768')  | Info: unique reference name for identification | Currently set to : sent_small_bert_L12_768\n",
            ">>> component_list['sentiment_dl@sent_small_bert_L12_768'] has settable params:\n",
            "component_list['sentiment_dl@sent_small_bert_L12_768'].setThreshold(0.6)                         | Info: The minimum threshold for the final result otheriwse it will be neutral | Currently set to : 0.6\n",
            "component_list['sentiment_dl@sent_small_bert_L12_768'].setThresholdLabel('neutral')              | Info: In case the score is less than threshold, what should be the label. Default is neutral. | Currently set to : neutral\n",
            "component_list['sentiment_dl@sent_small_bert_L12_768'].setEngine('tensorflow')                   | Info: Deep Learning engine used for this model | Currently set to : tensorflow\n",
            "component_list['sentiment_dl@sent_small_bert_L12_768'].setClasses(['positive', 'negative'])      | Info: get the tags used to trained this SentimentDLModel | Currently set to : ['positive', 'negative']\n",
            "component_list['sentiment_dl@sent_small_bert_L12_768'].setStorageRef('sent_small_bert_L12_768')  | Info: unique reference name for identification | Currently set to : sent_small_bert_L12_768\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-CdcbSd7WEpm"
      },
      "source": [],
      "execution_count": null,
      "outputs": []
    }
  ]
}